﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using MixScript.BLL.FI;
using System.Data;
using System.Globalization;

namespace MixScriptWeb.Accounting.ReportObject
{
    public partial class frmSubsidiaryLedger : cCommonWeb, IMIxCommon // System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            { LoadData(); }

        }
        public bool isvalid()
        { return true; }
        private void LoadData()
        {
            DataTable dt = new DataTable();
            rptGeneralJournal gj = new rptGeneralJournal();
            gj.getActivePeriod(out dt);
            //FillDropDownList(ddlPeriod, dt, "Name", "ID", true);
            FillDropDownList(ddlCurrency, "mst_currency", "currency", "currency", true);
        }


        protected void rbPeriod_CheckedChanges(Object sender, EventArgs e)
        {
            //ddlPeriod.Enabled = rbPeriod1.Checked;
            //txtFrom.Enabled = rbPeriod2.Checked;
            //txtTo.Enabled = rbPeriod2.Checked;

        }
        protected void lbSub_CheckedChanges(Object sender, EventArgs e)
        {
            DataSet ds = new DataSet();
            int ind = Convert.ToInt32(lbSub.SelectedItem.Value);
            rptSubsidiary sl = new rptSubsidiary();
            ds = sl.GetData(ind);
            if (ind == 1)
            {
                gvList.DataSource = ds.Tables[0];
            }
            else
            {
                gvSub.DataSource = ds.Tables[0];
                gvList.DataSource = ds.Tables[1];
            }
            gvSub.DataBind();
            gvList.DataBind();

        }
        protected void chkAllHeader_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox chkAll = new CheckBox();
            CheckBox chk;
            chkAll = (CheckBox)gvList.HeaderRow.Cells[0].FindControl("chkAllHeader");
            for (int i = 0; i < gvList.Rows.Count; i++)
            {
                chk = new CheckBox();
                chk = (CheckBox)gvList.Rows[i].Cells[0].FindControl("chkAll");
                chk.Checked = chkAll.Checked;

            }
        }
        protected void btnSubmit_Click(Object sender, EventArgs e)
        {


            String param = "";
            for (int i = 0; i < gvList.Rows.Count; i++)
            {
                CheckBox chk = new CheckBox();
                chk = (CheckBox)gvList.Rows[i].Cells[0].FindControl("chkAll");
                if (chk.Checked)
                {
                    if (param == "")
                        param = gvList.Rows[i].Cells[1].Text.TrimEnd();
                    else
                        param = param + "," + gvList.Rows[i].Cells[1].Text.TrimEnd();
                }
            }
            param = "";
            Session["ledgerAcc"] = param;
            for (int i = 0; i < gvSub.Rows.Count; i++)
            {
                CheckBox chk = new CheckBox();
                chk = (CheckBox)gvSub.Rows[i].Cells[0].FindControl("chkAll");
                if (chk.Checked)
                {
                    if (param == "")
                        param = gvSub.Rows[i].Cells[1].Text.TrimEnd();
                    else
                        param = param + "," + gvSub.Rows[i].Cells[1].Text.TrimEnd();
                }
            }
            Session["ledgerSub"] = param;
            //if (rbPeriod1.Checked)
            //{
            //    Session["fromParam"] = null;
            //    Session["toParam"] = null;
            //}
            //{
            Session["fromParam"] = Convert.ToDateTime(txtFrom.Text, new CultureInfo("ru-RU"));
            Session["toParam"] = Convert.ToDateTime(txtTo.Text, new CultureInfo("ru-RU"));
            //}



            ScriptManager.RegisterStartupScript(this, typeof(string), "OPEN_WINDOW",
                "window.open( '/Accounting/ReportObject/rpt_Subsidiary.aspx', null, '' );", true);

        }
    }
}